package io.renren.modules.sys.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.renren.modules.sys.dao.SysRoleLocationDao;
import io.renren.modules.sys.entity.SysRoleLocationEntity;
import io.renren.modules.sys.service.SysRoleLocationService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;



@Service("sysRoleLocationService")
public class SysRoleLocationServiceImpl extends ServiceImpl<SysRoleLocationDao, SysRoleLocationEntity> implements SysRoleLocationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysRoleLocationEntity> page = this.page(
                new Query<SysRoleLocationEntity>().getPage(params),
                new QueryWrapper<SysRoleLocationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveOrUpdate(Long roleId, List<String> szds) {
        baseMapper.delete(new UpdateWrapper<SysRoleLocationEntity>().eq("role_id",roleId.intValue()));
        if(CollectionUtil.isNotEmpty(szds)){
            szds.forEach(szd->{
                SysRoleLocationEntity roleLocationEntity=new SysRoleLocationEntity();
                roleLocationEntity.setRoleId(roleId.intValue());
                roleLocationEntity.setLocation(szd);
                baseMapper.insert(roleLocationEntity);
            });
        }
    }

}
